/*
 * @Descripttion: 出手鸭小程序
 * @version:1.0.1 
 * @Author: HHL
 * @Date: 2023-09-26 15:17:23
 * @LastEditTime: 2025-08-11 23:34:34
 * @LastEditors: sueRimn
 */
// 应用信息

import { fetchDeviceInfo } from 'api'

const state = {
  systemInfo: {}, // 系统信息

  visitDeviceInfo: {}, // 当前设备信息
}

const mutations = {
  // 更新系统信息
  UPDATE_SYSTEMINFO: (state, data) => {
    state.systemInfo = data
  },

  // 更新当前设备信息
  UPDATE_DEVICE_INFO: (state, data) => {
    state.visitDeviceInfo = data
  },
}

const actions = {
  // 获取系统信息
  getSystemInfo({ commit }) {
    uni.getSystemInfo({
			success: res => {
				const rate = res.windowHeight / res.windowWidth;
				const limit = res.windowHeight === res.screenHeight ? 1.8 : 1.65; // 临界判断值
				res.fullScreen = rate > limit

        commit('UPDATE_SYSTEMINFO', res)
			}
		})
  },

  // 获取本机信息
  loadVisitDeviceInfo({ commit, state },{userId}) {
    return new Promise(resolve => {
      fetchDeviceInfo({
        deviceBrand: state.systemInfo.brand||"",
        deviceName: state.systemInfo.model,
        deviceSystem: state.systemInfo.system,
        userId
      }).then(({ data, code }) => {
        if (code === 200 && data && data.productId) {
          const info = { ...data }
          commit('UPDATE_DEVICE_INFO', info)
          resolve(info)
        } else {
          resolve({})
        }
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}